import { defineStore } from 'pinia'
import { ref } from 'vue'

const Types = {
  SET_TOKEN: 'setToken',
  SET_USER: 'setUser',
  SET_USERavatar: 'setUserAvatar',
  SET_USERrealName: 'setUserRealName'
}

export const useUserStore = defineStore('user', () => {
  const user = ref({
    username: '',
    avatar: '',
    status: '',
    id: '',
    realname: '',
    email: ''
  })
  const isToken = ref(false)
  const playConfig = ref({
    isplay: false,
    playImg: '',
    playSinger: '',
    playSongName: '',
    totalTime: '',
    currentTime: '',
    playSrc: ''
  })

  function changePlayInfo(songInfo) {
    playConfig.value = songInfo
  }
  function changeCurrentTime() {
    playConfig.value.currentTime = parseInt(playConfig.value.currentTime + '') + 100 + ''
  }
  function setToken(payload) {
    if (payload) {
      isToken.value = payload
    } else {
      isToken.value = false
    }
  }
  function setUser(payload) {
    ;(user.value.username = payload.username),
      (user.value.avatar = payload.avatar),
      (user.value.status = payload.status),
      (user.value.id = payload.id),
      (user.value.realname = payload.realname),
      (user.value.email = payload.email)
  }
  function setUserAvatar(payload) {
    user.value.avatar = payload
  }
  function setUserRealName(payload) {
    user.value.realname = payload
  }
  return {
    user,
    isToken,
    playInfo: playConfig,
    changePlayInfo,
    changeCurrentTime,
    setToken,
    setUser,
    setUserAvatar,
    setUserRealName
  }
})
